package day06;

import java.util.Scanner;

public class CalTotalAvg {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入有几位评委");
        int num = scan.nextInt();
        double[] scores = inputData(num);
        double cal = calAvg(scores);
        if (cal !=0){
            System.out.println("评委的给出的平均分是:" + cal);
        }else{
            System.out.println("评委弃权严重所有成绩无效" );
        }



    }

    public static double[] inputData(int a) {
        int wro = 0;
        double[] scores = new double[a];
        Scanner scan = new Scanner(System.in);
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请填写第" + (i + 1) + "位的成绩");
            scores[i] = scan.nextDouble();
//            System.out.println(scores[i]);
            if (scores[i] > 10 || scores[i] < 0) {
//                System.out.println("进入判断输入错误");
                for (int j = 1; j <= 2; j++) {
//                    System.out.println("进入循环");
                    if (j == 1) {
//                        System.out.println("重新填写");
                        System.out.println("输入不合法,请重第" + (i + 1) + "位的成绩");
                        scores[i] = scan.nextDouble();
                        if (scores[i] > 10 || scores[i] < 0) {
                            System.out.println("输入依旧不合法" + (i + 1) + "位的自动弃权");
                            scores[i] = 0.0;
                            wro += 1;
                        } else {
//                            System.out.println("二次判断正确");
                            break;
                        }
                    }
                }

            } else {
//                System.out.println("进入判断输入正确");
            }

            if (wro > scores.length/2){
                for (int l = 0 ;l<scores.length;l++){
                    scores[i] = 0;
                }
                return scores;
            }
        }
        return scores;
    }

    public static double calAvg(double[] scores) {
        double num = 0.0;
        for (int i = 0; i < scores.length; i++) {
            num += scores[i];
        }
        if (num != 0){
            return num /= scores.length;
        }else {
            return 0;
        }

    }
}
